"""Server-rendered UI routes."""

from __future__ import annotations

from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse, RedirectResponse
from fastapi.templating import Jinja2Templates

templates = Jinja2Templates(directory="app/templates")

ui_router = APIRouter(include_in_schema=False)


@ui_router.get("/", response_class=HTMLResponse)
async def root() -> RedirectResponse:
    """Redirect root visitors to the main dashboard."""
    return RedirectResponse(url="/ui/projects", status_code=302)


@ui_router.get("/ui/login", response_class=HTMLResponse)
async def login_page(request: Request) -> HTMLResponse:
    """Render the login page shell."""
    return templates.TemplateResponse("auth/login.html", {"request": request})


@ui_router.get("/ui/projects", response_class=HTMLResponse)
async def projects_page(request: Request) -> HTMLResponse:
    """Render the project workspace shell."""
    return templates.TemplateResponse("projects/index.html", {"request": request})


@ui_router.get("/ui/operations", response_class=HTMLResponse)
async def operations_page(request: Request) -> HTMLResponse:
    """Render the operations console placeholder."""
    return templates.TemplateResponse("operations/index.html", {"request": request})


@ui_router.get("/ui/test/datatable", response_class=HTMLResponse)
async def test_datatable_page(request: Request) -> HTMLResponse:
    """Render the DataTable component test page."""
    return templates.TemplateResponse("test_datatable.html", {"request": request})


@ui_router.get("/ui/test/boxplot", response_class=HTMLResponse)
async def test_boxplot_page(request: Request) -> HTMLResponse:
    """Render the BoxplotChart component test page."""
    return templates.TemplateResponse("test_boxplot.html", {"request": request})

